package lvm

import "context"

// VGExtend 添加物理磁盘到存储池
func VGExtend(ctx context.Context, vgName string, pvName string) (vg *VolumeGroup, err error) {
	// 前置条件检查
	if err = isPVJoinable(ctx, pvName); err != nil {
		return
	}
	vg = getVG(ctx, vgName)
	if vg == nil {
		err = ErrNotFound
		return
	}

	_, err = execCommand(ctx, "vgextend", vgName, pvName)
	if err != nil {
		return
	}

	vg = getVG(ctx, vgName)
	if vg == nil {
		err = ErrCommand
		return
	}
	return
}
